%-------------------------------------------------------------------------
% Subroutine: Computation Boom and Bust size
%
% Estimation Codes for State-Level Results in  
% Ben-David, Itzhak, Sebastian Weber, and Pascal Towbin 
% "Inferring Expectations from Observables: Evidence from the Housing Market" 
% Review of Economics and Statistics
% ------------------------------------------------------------------------ 

%% Boom
% all valid rotations
coll_boomsize=coll_realdata(n_decomp,peakdate,:)-coll_realdata(n_decomp,troughdate,:);
coll_speccontrib=squeeze(coll_histirf(n_decomp,peakdate,4,:,:))-squeeze(coll_histirf(n_decomp,troughdate,4,:,:));
coll_intcontrib=squeeze(coll_histirf(n_decomp,peakdate,3,:,:))-squeeze(coll_histirf(n_decomp,troughdate,3,:,:));
coll_demandcontrib=squeeze(coll_histirf(n_decomp,peakdate,2,:,:))-squeeze(coll_histirf(n_decomp,troughdate,2,:,:));
coll_supplycontrib=squeeze(coll_histirf(n_decomp,peakdate,1,:,:))-squeeze(coll_histirf(n_decomp,troughdate,1,:,:));
coll_nondet_boomsize=sum(squeeze(coll_histirf(n_decomp,peakdate,1:5,:,:))-squeeze(coll_histirf(n_decomp,troughdate,1:5,:,:)),1);

% mean
boomsize=coll_realdata(n_decomp,peakdate,:)-coll_realdata(n_decomp,troughdate,:);
speccontrib=squeeze(coll_hist_mean(n_decomp,peakdate,4,:))-squeeze(coll_hist_mean(n_decomp,troughdate,4,:));
intcontrib=squeeze(coll_hist_mean(n_decomp,peakdate,3,:))-squeeze(coll_hist_mean(n_decomp,troughdate,3,:));
demandcontrib=squeeze(coll_hist_mean(n_decomp,peakdate,2,:))-squeeze(coll_hist_mean(n_decomp,troughdate,2,:));
supplycontrib=squeeze(coll_hist_mean(n_decomp,peakdate,1,:))-squeeze(coll_hist_mean(n_decomp,troughdate,1,:));
nondet_boomsize=sum(squeeze(coll_hist_mean(n_decomp,peakdate,1:5,:))-squeeze(coll_hist_mean(n_decomp,troughdate,1:5,:)),1);

%% Bust
bustsize=coll_realdata(n_decomp,peakdate,:)-coll_realdata(n_decomp,troughdate2,:);